<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Crop / CropBottom Avisynth Filter</title>
   <link rel="stylesheet" type="text/css" href="../../avisynth.css">
</head>
<body >
<h2>
<a NAME="Crop"></a>Crop
/ CropBottom
</h2>
<p><code>Crop </code>(<var>clip, int left, int top, int width, int height,
bool &quot;align</var>&quot;)<br>
  <code>Crop </code>(<var>clip, int left, int top, int -right, int -bottom,
bool &quot;align&quot;</var>)<br>
  <code>CropBottom </code>(<var>clip, int count, bool align</var>)
<p><code>Crop</code> crops excess pixels off of each frame.
<p> If your source
video has 720x480 resolution, and you want to reduce it to 352x240 for
VideoCD, here's the correct way to do it:
<pre># Convert CCIR601 to VCD, preserving the correct aspect ratio
ReduceBy2
Crop(4,0,352,240)</pre>
See <a href="convert.htm">colorspace conversion filters</a>
for limitations when using different color formats.
<p>If a negative value is entered in the <var>width</var> and <var>height</var>
these are also treated as offsets. For example:
<pre># Crop 16 pixels all the way around the picture, regardless of image size:
Crop(16,16,-16,-16)</pre>
<p>In <em>v2.53</em> an option <var>align</var> (false by default) is added:<br>
  Cropping an YUY2/RGB32 image is always mod4 (four bytes). However, when reading
x bytes (an int), it is faster when the read is aligned to a modx placement in
memory. MMX/SSE likes 8-byte alignment and SSE2 likes 16-byte alignment. If the
data is NOT aligned, each read/write operation will be delayed at least 4
cycles. So images are always aligned to mod16 when they are created by AviSynth.<br>
  <br>
If an image has been cropped, they will sometimes be placed unaligned in memory
- &quot;<var>align</var> = true&quot; will copy the entire frame from the unaligned memory
placement to an aligned one. So if the penalty of the following filter is larger
than the penalty of a complete image copy, using &quot;<var>align</var> = true&quot; will be
faster. Especially when it is followed by smoothers.<br>
  <br>
The alternative <code>CropBottom</code> syntax is useful for cropping garbage
off the bottom of a clip captured from VHS tape. It removes <var>count</var>
lines from the bottom of each frame.
</p>
<h2><span class="mw-headline">Memory alignment</span></h2>
<p>In v2.53 an option <i>align</i> (false by default) is added:</p>
<p>Cropping an YUY2/RGB32 image is always mod4 (four bytes). However, when
reading x bytes (an int), it is faster when the read is aligned to a modx
placement in memory. MMX/SSE likes 8-byte alignment and SSE2 likes 16-byte
alignment. If the data is NOT aligned, each read/write operation will be delayed
at least 4 cycles. So images are always aligned to mod16 when they are created
by AviSynth.</p>
<p>If an image has been cropped, they will sometimes be placed unaligned in
memory - &quot;align = true&quot; will copy the entire frame from the unaligned
memory placement to an aligned one. So if the penalty of the following filter is
larger than the penalty of a complete image copy, using &quot;align=true&quot;
will be faster. Especially when it is followed by smoothers.</p>
<a name="Crop_restrictions"></a>
<h2><span class="mw-headline">Crop restrictions</span></h2>
<p>In order to preserve the data structure of the different colorspaces, the
following mods should be used. You will not get an error message if they are not
obeyed, but it may create strange artifacts. For a complete discussion on this,
see <font color="#FF0000">DataStorageInAviSynth ...</font></p>
<table border="1" width="50%">
  <tr>
    <td width="25%" rowspan="2" align="center"><b>Colorspace</b></td>
    <td width="25%" rowspan="2" align="center"><b>Width</b></td>
    <td width="50%" colspan="2" align="center"><b>Height</b></td>
  </tr>
  <tr>
    <td width="25%" align="center"><b>progressive video</b></td>
    <td width="25%" align="center"><b>interlaced video</b></td>
  </tr>
  <tr>
    <td width="25%">RGB</td>
    <td width="25%"><i>no restriction</i></td>
    <td width="25%"><i>no restriction</i></td>
    <td width="25%">mod-2</td>
  </tr>
  <tr>
    <td width="25%">YUY2</td>
    <td width="25%">mod-2</td>
    <td width="25%"><i>no restriction</i></td>
    <td width="25%">mod-2</td>
  </tr>
  <tr>
    <td width="25%">YV12</td>
    <td width="25%">mod-2</td>
    <td width="25%">mod-2</td>
    <td width="25%">mod-4</td>
  </tr>
</table>
<p>NOTE: The <a href="resize.htm">resize functions</a> optionally allow fractional pixel cropping  of the
input frame, this results in a weighting being applied to the edge pixels
being resized.&nbsp; These options may be used if the mod-n format dimension
restriction of crop are inconvienient. In sum -- "For cropping off hard artifacts like VHS head noise or leterbox borders always use Crop. For extracting a portion of an image and to maintain accurate edge resampling use the resize cropping parameters." (<a href="http://forum.doom9.org/showthread.php?s=&amp;threadid=91630">Doom9
thread</a>)</p>
<p><kbd>$Date: 2009/09/12 15:10:22 $</kbd></p>
<form><input TYPE="Button" VALUE="Back"
onClick="history.go(-1)"></form>
</body>
</html>
